

ALTER     procedure save_calendar
	@year varchar(6),
	@firstDay datetime,
	@lastDay datetime,
	@NumberOfPeriods int,
	@JITWindow int,
	@WW_START_DATE DATETIME,	
	@yearID bigint OUTPUT
as	
Begin
	declare @count int
	declare @temp_YearID int	
	
	select @count = Count(*) from Company_Calendar where CC_Year = @year	
	
	if ( @count > 0 )
		begin
			delete from Company_Quarterly_Calendar where CQC_YearID = (select CC_YearID from Company_Calendar where CC_Year = @year)
			delete from Company_Calendar where CC_Year = @year
		end
	
	insert into Company_Calendar(CC_Year,CC_Start_Date,CC_End_Date,CC_NO_Of_Periods,CC_JIT_WINDOW,WW_START_DATE) values( @year, @firstDay, @lastDay, @NumberOfPeriods, @JITWindow, @WW_START_DATE )
	set @temp_yearID = @@identity	

	set @yearID = @temp_yearID
	

 select @yearID
end
